package com.hongshan.wallet.core.wallet

import android.app.Application
import android.databinding.ObservableField
import android.view.View
import com.hongshan.wallet.R
import com.hongshan.wallet.base.BaseOnPageChangeListener
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.base.SingleLiveEvent
import com.hongshan.wallet.format

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.wallet
 * @author   : zhangxx
 * @date     : 2019/3/28
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */
class CommissionViewModel(application: Application) : MyViewModel(application) {

    val startTimeStr = ObservableField("开始时间")
    var startTime: Long? = null
    val endTimeStr = ObservableField("结束时间")
    var endTime: Long? = null
    val selectTime = ObservableField(System.currentTimeMillis()/1000)
    val datePickerStatus = ObservableField(false)

    val refreshData = SingleLiveEvent<Unit>()

    var clickId = 0

    val index = ObservableField(0)

    var type: Int = 1

    val pagerChange = BaseOnPageChangeListener{
        refreshData.call()
    }

    val showPicker = View.OnClickListener {
        clickId = it.id
        datePickerStatus.set(true)
    }

    val pickerOK = View.OnClickListener {
        if (clickId == R.id.tvStartTime) {
            startTime = selectTime.get()
            startTimeStr.set(selectTime.get()?.format())
        } else {
            endTime = selectTime.get()
            endTimeStr.set(selectTime.get()?.format())
        }
        datePickerStatus.set(false)
        refreshData.call()
    }
    val pickerCancle = View.OnClickListener {
        datePickerStatus.set(false)
        clickId = 0
    }
}